package guoanmaker.personal.business.controller;

import java.io.File;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.mysql.fabric.Response;

import guoanmaker.personal.business.model.PersonalPicCode;
import guoanmaker.personal.business.model.PersonalUser;
import guoanmaker.personal.business.model.ReturnResult;
import guoanmaker.personal.business.modelnobind.PersonalUserForUser;
import guoanmaker.personal.business.service.PersonalAddressService;
import guoanmaker.personal.business.service.PersonalCodeService;
import guoanmaker.personal.business.service.PersonalPicCodeService;
import guoanmaker.personal.business.service.PersonalUserCouponService;
import guoanmaker.personal.business.service.PersonalUserService;
import guoanmaker.personal.helper.common.AjaxJson;
import guoanmaker.personal.helper.common.abstractobj.ApiController;
import guoanmaker.personal.helper.common.util.SystemHelper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import redis.clients.jedis.Jedis;

/**
 * 
* @ClassName: PersonalUserController 
* @Description: 用户controller
* @author Yvonne_MGL
* @date 2017年7月6日 下午3:38:07 
*  
 */
@RestController
@RequestMapping(ApiController.USER_URL)
public class PersonalUserController {
	
	@Resource
	private PersonalUserService personalUserService;
	
	@Resource
	private AjaxJson ajaxJson;
	
	@Resource
	private PersonalCodeService personalCodeService;
	
	@Resource
	private PersonalAddressService PersonalAddressService;
	
	@Resource
	private PersonalPicCodeService personalPicCodeService;
	
	@Resource
	private PersonalUserCouponService personalUserCouponService;
	
	@Autowired  
	private  HttpServletRequest request;
	
	@Autowired  
	private  HttpServletResponse response;
	
	/**
	 * 
	* @Description: 将用户设置为服务商 
	* @param userid 用户id
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:38:23     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "成为服务商", notes = "成为服务商")
	@RequestMapping(value = "/beProvider", method = RequestMethod.POST)
	public AjaxJson beProvider(String userid,String state){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(state!=null&&state.equals("1")&&(value==null||!value.equals("1"))){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=personalUserService.beProvider(userid,state);
				PersonalUserForUser user=personalUserService.findById(userid);
				if(state!=null&&state.equals(4)){
					request.getSession().removeAttribute(sessionid);
					request.getSession().removeAttribute(user.getUsername()+sessionid);
				}
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
				e.printStackTrace();
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 注册用户
	* @param username 用户名,即手机号
	* @param password 密码
	* @param code 验证码
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:39:03     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "注册接口", notes = "注册")
	@RequestMapping(value = "/registered", method = RequestMethod.POST)
	public AjaxJson registeredUser(String username, String password,String code) {
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=personalUserService.registeredUser(username, password,code,"1");
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 验证用户名密码 
	* @param username 用户名
	* @param password 密码
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:39:49     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "验证接口", notes = "验证用户名密码")
	@RequestMapping(value = "/verify", method = RequestMethod.POST)
	public AjaxJson verify(String username, String password) {
		ReturnResult returnResult=new ReturnResult();
		try {
			String sessionid=request.getSession().getId();
			Jedis jedis=new Jedis("123.56.48.63",6379); 
			jedis.auth("218007");
			jedis.set(sessionid, "1");
			String ss=jedis.get(username);
			if(ss==null){
				jedis.set(username, sessionid+",");
			}else{
				jedis.set(username, ss+sessionid+",");
			}
			jedis.disconnect();
			returnResult=personalUserService.verify(username, password,"1");
			returnResult.setSessionid(sessionid);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}

	/**
	 * 
	* @Description: 修改密码,重置密码
	* @param username 用户名
	* @param password 密码
	* @param code 验证码
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:40:19     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "修改密码接口", notes = "修改密码")
	@RequestMapping(value = "/changePassword", method = RequestMethod.POST)
	public AjaxJson changePassword(String username, String password,String code) {
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=personalUserService.changePassword(username, password,code);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}

	/**
	 * 
	* @Description: 修改个人资料
	* @param userid 用户id
	* @param portraitFile  头像图片
	* @param nickname 昵称
	* @param birthday 生日
	* @param name 姓名
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:40:58     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "修改资料接口", notes = "修改用户资料")
	@RequestMapping(value = "/updateUser", method = RequestMethod.POST)
	@ApiImplicitParam(paramType = "form", name = "portraitFile", dataType = "File")
	public AjaxJson updateUser(String userid, String portraitFile, String nickname,
			String birthday,String name) {
		PersonalUserForUser personalUser=new PersonalUserForUser();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(personalUser);
		}else{
			try {
				personalUser=personalUserService.updateUser(userid, portraitFile, nickname, birthday,name);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(personalUser);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(personalUser);
			}
		}
		
		return ajaxJson;
	}

	/**
	 * 
	* @Description: 查询用户资料 
	* @param userid 用户id
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:41:50     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "查询用户接口", notes = "查询用户资料")
	@RequestMapping(value = "/findById", method = RequestMethod.POST)
	public AjaxJson findById(String userid) {
		PersonalUserForUser personalUser=new PersonalUserForUser();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(personalUser);
		}else{
			try {
				personalUser=personalUserService.findById(userid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(personalUser);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(personalUser);
				e.printStackTrace() ;
			}
		}
		
		return ajaxJson;
	}

	/**
	 * 
	* @Description: 发送验证码
	* @param telephone 电话
	* @param isuser 判断用户存在发验证码传1,用户不存在发验证码传2,存不存在都发传0
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:42:18     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "发送验证码接口", notes = "发送验证码")
	@RequestMapping(value = "/sendVerificationCode", method = RequestMethod.POST)
	public AjaxJson sendVerificationCode(String telephone,String isuser) {
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=personalUserService.sendVerificationCode(telephone,isuser);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 手机快捷登陆
	* @param username 用户名
	* @param code 验证码
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:43:31     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "手机快捷登陆接口", notes = "手机快捷登陆")
	@RequestMapping(value = "/fastLanding", method = RequestMethod.POST)
	public AjaxJson fastLanding(String username,String code){
		ReturnResult returnResult=new ReturnResult();
		try {
			String sessionid=request.getSession().getId();
			Jedis jedis=new Jedis("123.56.48.63",6379); 
			jedis.auth("218007");
			jedis.set(sessionid, "1");
			String ss=jedis.get(username);
			if(ss==null){
				jedis.set(username, sessionid+",");
			}else{
				jedis.set(username, ss+sessionid+",");
			}
			jedis.disconnect();
			returnResult=personalUserService.fastLanding(username, code,"1");
			returnResult.setSessionid(sessionid);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 注销用户 
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:44:00     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "注销接口", notes = "注销")
	@RequestMapping(value = "/signOut", method = RequestMethod.POST)
	public AjaxJson signOut(){
		try {
			String sessionid=request.getSession().getId();
			String sessionid1=request.getHeader("Authorization");
			if(sessionid1!=null){
				sessionid=sessionid1.substring(7,sessionid1.length());
			}
			Jedis jedis=new Jedis("123.56.48.63",6379); 
			jedis.auth("218007");
			jedis.del(sessionid);
			jedis.disconnect();
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(null);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(null);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description:对比验证码是否一致
	* @param username 手机号
	* @param code 验证码
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:44:19     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "验证验证码接口", notes = "验证验证码")
	@RequestMapping(value = "/verifyCode", method = RequestMethod.POST)
	public AjaxJson verifyCode(String username,String code){
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=personalCodeService.verifyCode(username, code);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 冻结解冻用户 
    * @param userid 用户id
    * @param state 操作状态 0为解冻   1为冻结
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月25日 上午11:17:32     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "冻结解冻用户", notes = "冻结解冻用户")
	@RequestMapping(value = "/freezeOrNotUser", method = RequestMethod.POST)
	public AjaxJson freezeOrNotUser(String userid,String state){
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=personalUserService.freezeOrNotUser(userid, state);
			if(state!=null&&state.equals("1")){
				PersonalUserForUser user=personalUserService.findById(userid);
				SystemHelper.removeRedis(user.getUsername());
			}
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	 }
	
	/**
     * 
    * @Description: 保存用户的渠道来源 
    * @param userid 用户id
    * @param channelSource 来源
    * @param @return
    * @author Yvonne_MGL 
    * @date 2017年11月10日 上午7:11:30     
    * @return ReturnResult    
    * @throws 
     */
	@ApiOperation(value = "保存用户的渠道来源", notes = "保存用户的渠道来源")
	@RequestMapping(value = "/setSource", method = RequestMethod.POST)
	public AjaxJson setSource(String userid,String channelSource){
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=personalUserService.setSource(userid, channelSource);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 保存地址 
	* @param name 姓名
	* @param address 地址
	* @param telephone 电话
	* @param isdefault 是否为默认0为否 1为是
	* @param user_id 用户id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月16日 上午11:19:34     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "保存用户地址", notes = "保存用户地址")
	@RequestMapping(value = "/saveAddress", method = RequestMethod.POST)
	public AjaxJson saveAddress(String name,String address,String telephone,String isdefault,String user_id) {
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=PersonalAddressService.saveAddress(name, address, telephone, isdefault, user_id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 删除地址
	* @param @param id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月16日 下午1:54:58     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "删除地址接口", notes = "删除地址")
	@RequestMapping(value = "/deleteAddress", method = RequestMethod.POST)
	public AjaxJson deleteAddress(String id) {
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=PersonalAddressService.deleteAddress(id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 保存地址 
	* @param name 姓名
	* @param address 地址
	* @param telephone 电话
	* @param isdefault 是否为默认0为否 1为是
	* @param id 地址id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月16日 下午2:11:38     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "保存用户地址", notes = "保存用户地址")
	@RequestMapping(value = "/updateAddress", method = RequestMethod.POST)
	public AjaxJson updateAddress(String name,String address,String telephone,String isdefault,String id) {
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=PersonalAddressService.updateAddress(name, address, telephone, isdefault, id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
				e.printStackTrace();
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 修改密码 
    * @param userid 用户id
    * @param oldPassword 旧密码
    * @param newPassword 新密码
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月28日 下午1:57:48     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "修改用户密码", notes = "修改用户密码")
	@RequestMapping(value = "/changeUserPassword", method = RequestMethod.POST)
	public AjaxJson changeUserPassword(String userid,String oldPassword,String newPassword){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=personalUserService.changeUserPassword(userid, oldPassword, newPassword);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 生成图片验证码 
	* @param response
	* @author Yvonne_MGL 
	* @date 2017年9月12日 下午2:12:12     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "获取图片验证码", notes = "获取图片验证码")
	@RequestMapping(value = "/getPicCode", method = RequestMethod.POST)
	public AjaxJson getPicCode(){
		PersonalPicCode picCode=new PersonalPicCode();
		try {
			picCode=personalPicCodeService.getPicCode();
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(picCode);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(picCode);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 验证图片验证码，验证成功发送短信验证码 
	* @param id 图片验证码id
	* @param code 用户输入的图片验证码
	* @param telephone 电话号码
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年9月12日 下午2:36:45     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "验证图片验证码", notes = "验证图片验证码")
	@RequestMapping(value = "/verifyPicCode", method = RequestMethod.POST)
	public AjaxJson verifyPicCode(String id,String code,String telephone){
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=personalPicCodeService.verifyPicCode(id, code, telephone);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 初始化双11优惠券数据
	* @param id 运营优惠券类别id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年11月3日 上午11:20:00     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "初始化双11优惠券数据", notes = "初始化双11优惠券数据")
	@RequestMapping(value = "/initializeUserCoupons", method = RequestMethod.POST)
	public AjaxJson initializeUserCoupons(String id,String startDate,String endDate){
		try {
			personalUserCouponService.initializeUserCoupons(id,startDate,endDate);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData("初始化完成");
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("初始化失败");
		}
		return ajaxJson;
	}
	/**
	 * 
	 * @Title: getSessionByUserId
	 * @Description: 根据用户id获取Session
	 * @param userid 用户id
	 * @return AjaxJson 
	 * @throws
	 */
	@ApiOperation(value = "根据用户id获取Session", notes = "根据用户id获取Session")
	@PostMapping("/getSessionByUserId")
	public AjaxJson getSessionByUserId(String userid) {
		Jedis jedis = new Jedis("123.56.48.63", 6379);
		jedis.auth("218007");
		try {
			String userName = personalUserService.getUserNameById(userid);
			String value = jedis.get(userName);
			if (value == null || "".equals(value)) {
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData("查询结果为空");
			} else {

				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(value.substring(0, value.indexOf(",")));
			}
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
			e.printStackTrace();
		} finally {
			jedis.disconnect();
		}
		return ajaxJson;
	}
}
